<!-- 其他页面拷贝这个模板 -->
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>论坛中文网 - 登录</title>
</head>

<body>

  <div class="page-header" style="padding-left: 200px;">
    <h1 onclick="window.location.replace('/');" style="cursor: pointer;">论坛中文网 <small>欢迎登录</small></h1>
  </div>

  <form class="form-horizontal" role="form" style="max-width: 600px; margin-left: 200px;">
    <div class="form-group">
      <label for="mobile" class="col-sm-2 control-label">手机号</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="mobile" placeholder="请输入手机号">
      </div>
    </div>
    <div class="form-group">
      <label for="password" class="col-sm-2 control-label">密码</label>
      <div class="col-sm-10">
        <input type="password" class="form-control" id="password" placeholder="请输入密码">
      </div>
    </div>
    <div class="form-group">
      <div class="col-sm-offset-2 col-sm-10">
        <div class="checkbox">
          <label>
            <input type="checkbox">请记住我
          </label>
        </div>
      </div>
    </div>
    <div class="form-group">
      <div class="col-sm-offset-2 col-sm-10">
        <!-- submit提交form标签，触发js方法，应该改为button -->
        <button type="button" class="btn btn-default" onclick="login();">登录</button>
        <a href="/html/register.html"> 没有账号?立即注册</a>
      </div>
    </div>
  </form>

</body>

<!-- 引入jquery -->
<script src="/js/jquery/jquery-1.10.2.min.js"></script>
<!-- 引入bootstrap -->
<link href="/js/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src="/js/bootstrap/js/bootstrap.min.js"></script>
<!-- 引入main.js -->
<script src="/js/main.js"></script>

<script>

  /**
   * 登录方法
   */
  function login() {
    // 拼一个user对象
    let user={
      "mobile": $("#mobile").val(),
      "password": $("#password").val()
    }
  
    $.ajax({
      url: BACK_URL + "/login",
      method: "post",
      contentType:"application/json;charset=utf-8",
      data: JSON.stringify(user),
      success:function (result) {
        if(result.code==200) {
          window.location.replace("/");// 跳转到主页
        }
      }
    })
  }
  
  </script>

</html>